package com.weilan.ark3.utils;

import com.weilan.ark3.common.GlobalParam;

public class CollectUtils {
    public static short getState(short Inception, short data) {
        if (data == 2 || Inception == 2) {
            Inception = 2;
        } else if (data == 3 && Inception == 3) {
            Inception = 3;
        } else {
            Inception = 1;
        }
        return Inception;
    }

    //获取汇总模式
    public static short getMode(short Inception, short data) {
        if (GlobalParam.PVState != 1 && GlobalParam.backState != 1 && GlobalParam.fgState != 1  && data != 0) {
            Inception = data;//系统模式控制
        }
        return Inception;
    }

    //获取汇总相加的数据
    public static short getAdd(short Inception, short data) {
        return Inception += data;
    }

    //获取可写地址汇总系统状态
    public static short getRWState(short Inception, short data) {
        if (data == 6 || Inception == 6) {
            Inception = 6;
        } else {
            Inception = 2;
        }
        return Inception;
    }

    //控制权
    public static short getController(short Inception, short data) {
        if (data == 0 || Inception == 0) {
            Inception = 0;
        } else {
            Inception = 1;
        }
        return Inception;
    }

    public static int getAddElectricEnergy(int Inception, int data) {
        //电量数值为负值时取反
        if (data < 0) {
            data = 65536 + data;
        }
        int sum;
        sum = Inception + data;
        return sum;
    }

    public static short getSOCState(short Inception, short data) {
        if (data == 1 || Inception == 1) {
            Inception = 1;
        } else {
            Inception = 0;
        }
        return Inception;
    }
}
